/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nekocode.dividerdrawable.sample.slice;

import com.nekocode.dividerdrawable.DividerDrawable;
import com.nekocode.dividerdrawable.DividerLayout;
import com.nekocode.dividerdrawable.DividerUtils;
import com.nekocode.dividerdrawable.sample.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

/**
 * 主界面
 */
public class MainAbilitySlice extends AbilitySlice {
    private DividerDrawable dividerDrawable;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        DividerUtils.setContext(getContext());

        linear();

        text3();

        text4();
    }

    private void linear() {
        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setCenter(DividerLayout.CENTER_VERTICAL);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_linear1), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setMarginLeftDp(getContext(), 50)
                .setCenter(DividerLayout.CENTER_VERTICAL);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_linear2), dividerDrawable);
    }

    private void text3() {
        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setOrientation(DividerLayout.ORIENTATION_VERTICAL)
                .setAlign(DividerLayout.ALIGN_PARENT_RIGHT)
                .setMarginTopDp(getContext(), 16)
                .setMarginBottomDp(getContext(), 16);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text_3_1), dividerDrawable);

        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text_3_3), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setOrientation(DividerLayout.ORIENTATION_VERTICAL)
                .setAlign(DividerLayout.ALIGN_PARENT_RIGHT)
                .setMarginTopDp(getContext(), 32)
                .setMarginBottomDp(getContext(), 32);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text_3_2), dividerDrawable);
    }

    private void text4() {
        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setMarginLeftDp(getContext(), 16)
                .setLengthDp(getContext(), 100);

        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text4_1), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setOrientation(DividerLayout.ORIENTATION_VERTICAL)
                .setCenter(DividerLayout.CENTER_VERTICAL)
                .setLengthDp(getContext(), 46);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text4_1), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setCenter(DividerLayout.CENTER_HORIZONTAL)
                .setLengthDp(getContext(), 100);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text4_2), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setOrientation(DividerLayout.ORIENTATION_VERTICAL)
                .setAlign(DividerLayout.ALIGN_PARENT_RIGHT)
                .setCenter(DividerLayout.CENTER_VERTICAL)
                .setLengthDp(getContext(), 46);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text4_2), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setAlign(DividerLayout.ALIGN_PARENT_RIGHT)
                .setMarginRightDp(getContext(), 16)
                .setLengthDp(getContext(), 100);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text4_3), dividerDrawable);

        dividerDrawable = new DividerDrawable();
        dividerDrawable
                .setStrokeWidth(10)
                .setColor(0xFFFFFFFF)
                .getLayout()
                .setCenter(DividerLayout.CENTER_HORIZONTAL)
                .setLengthDp(getContext(), 300);
        DividerUtils.addDividersTo(findComponentById(ResourceTable.Id_text4_4), dividerDrawable);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
